package com.ehome.user.Activity.Login;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.ehome.user.Module.user;
import com.ehome.user.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

/**
 * Created by Administrator on 2018/3/8 0008.
 */

public class PasswordActivity extends AppCompatActivity {

    @Bind(R.id.edit_phone_reg)
    EditText edit_phone_reg;
    @Bind(R.id.edit_checknum_reg)
    EditText edit_checknum_reg;
    String phone;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pasw);
        ButterKnife.bind(this);
        phone=getIntent().getStringExtra("phone");
    }

    @OnClick({R.id.bt_fisinh,R.id.img_base_back})
    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.bt_fisinh:
                if(TextUtils.isEmpty(edit_phone_reg.getText().toString())){
                    Toast.makeText(PasswordActivity.this,"密码不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                if(!edit_phone_reg.getText().toString().equals(edit_checknum_reg.getText().toString())){
                    Toast.makeText(PasswordActivity.this,"两次密码不同",Toast.LENGTH_SHORT).show();
                    return;
                }
                user _user=new user();
                _user.setPhone(phone);
                _user.setPassword(edit_phone_reg.getText().toString());
                _user.save(new SaveListener<String>() {
                    @Override
                    public void done(String s, BmobException e) {
                        if(e==null){
                            Toast.makeText(PasswordActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                            finish();
                        }else {
                            Toast.makeText(PasswordActivity.this,"注册失败",Toast.LENGTH_SHORT).show();
                            finish();
                        }
                    }
                });
                break;
            case R.id.img_base_back:
                finish();
                break;
        }
    }
}
